package com.hb.trade.server.project.section.service.item;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hb.core.pojo.project.section.dto.BidSectionDTO;
import com.hb.core.pojo.project.section.entity.TradeSecondQuotationBidInfo;
import com.hb.trade.server.project.evaluation.service.EvaluationCommitteeBidService;
import com.hb.trade.server.project.section.service.raw.TradeSecondQuotationBidInfoService;
import org.springframework.stereotype.Service;

import static com.hb.core.pojo.enums.ButtonStatusEnum.DONE;
import static com.hb.core.pojo.enums.ButtonStatusEnum.NONE;

/**
 * 评标/评审
 * 按钮权限方法
 *
 * @author gaoyf
 * @since 2021-9-18 11:01
 */
@Service
public class EvaluationService {

    protected final TradeSecondQuotationBidInfoService secondQuotationBidInfoService;
    protected final EvaluationCommitteeBidService evaluationCommitteeBidService;

    public EvaluationService(TradeSecondQuotationBidInfoService secondQuotationBidInfoService,
                             EvaluationCommitteeBidService evaluationCommitteeBidService) {
        this.secondQuotationBidInfoService = secondQuotationBidInfoService;
        this.evaluationCommitteeBidService = evaluationCommitteeBidService;
    }

    /**
     * 评委会信息查看
     *
     * @param section
     * @return
     * @author zhaojk
     */
    public int judgesInfoView(BidSectionDTO section) {
        Long sectionId = section.getId();
        Integer evaluationCommitteeBidCount = evaluationCommitteeBidService.countEvaluationCommitteeBidBySectionId(sectionId);
        if (evaluationCommitteeBidCount > 0) {
            return DONE.getCode();
        }
        return NONE.getCode();
    }

    /**
     * 多轮报价
     *
     * @author zhaojk
     */
    public int multiWheelQuote(BidSectionDTO section) {
        QueryWrapper<TradeSecondQuotationBidInfo> wrapper = TradeSecondQuotationBidInfo.wrapper();
        wrapper.eq("section_id", section.getId())
                .eq("end_type", 1).last("limit 1");
        long count = secondQuotationBidInfoService.count(wrapper);
        if (count > 0) {
            return DONE.getCode();
        }
        return NONE.getCode();
    }

}
